package day4;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class homework {
    public static void main(String[] args) {
        //3.a
        int[] a=new int[]{-19,-2,-13,-8,-5,-11,-17,-8,-9,-10};
        for (int i=1;i<a.length;i++){
            if(a[i]>a[0]){
                int temp=a[i];
                a[i]=a[0];
                a[0]=temp;
            }
        }//用第一个值作为标兵
        System.out.println(Arrays.toString(a));

        //3.b

        int[] b=new int[]{10,2,13,4,5,6,7,8,9,10};
        int ji=0,max=b[0];
        int ou=0,min=b[0];
        for (int i=0;i<b.length;i++){
            if(b[i]%2==0){
                ou=b[i]+ou;
            }
            else {
                ji=b[i]+ji;
            }
        }
        for (int i=1;i<b.length;i++){
            if(max<b[i]){
                max=b[i];
            }
            if(min>b[i]){
                min=b[i];
            }
        }
        System.out.println("偶数和："+ou);
        System.out.println("奇数和："+ji);
        System.out.println("最大值："+max);
        System.out.println("最小值："+min);


        int[] c=new int[]{2,3,4,5,2,3,4,2,2,2,2};
        one:
        for (int j : c) {
            int count=0;
            two:
            for (int k : c) {
                if (j == k) {
                    count++;
                    if (count > c.length/2) {
                        System.out.println("出现超过一半："+j);
                         break one;
                    }
                }
            }
        }

        int size=0;
        int[] d=new int[5];
        boolean[] e= new boolean[11];
        for (int i=0;i<11;i++){
            e[i]=false;
        }
        for (int i=0;size<5;){
            Random random = new Random();
            int randomNumber = random.nextInt(10) + 1; // 生成1到10的随机数
            //1.Math类
            //random()生成0-1随机浮点数 [0.1)
            //floor() 向下取整
            //ceil 向下取整
            //2.random对象
            //nextInt(n) 生成0-n-1随机整数
            if (!e[randomNumber]){
            e[randomNumber]=true;
            d[i]=randomNumber;
            size++;
            i++;
            }
        }
        System.out.println(Arrays.toString(d));
    }
}
